package com.have.blog.web.controller;

import com.have.blog.base.wrapper.Wrapper;
import com.have.blog.web.dto.BlogDto;
import com.have.blog.web.service.WebBlogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Set;

@RestController
@RequestMapping("/sort")
@Api(value = "博客归档相关接口", tags = {"博客归档相关接口"})
@Slf4j
public class SortController {
    @Autowired
    private WebBlogService blogService;

    /**
     * 获取归档的信息
     */
    @ApiOperation(value = "归档", notes = "归档")
    @GetMapping("/getSortList")
    public Wrapper getSortList() {
        log.info("获取归档日期");
        Set<String> monthSet = blogService.getBlogTimeSortList();
        return Wrapper.success(monthSet);
    }

//    @BussinessLog(value = "点击归档", behavior = EBehavior.VISIT_SORT)
    @ApiOperation(value = "通过月份获取文章", notes = "通过月份获取文章")
    @GetMapping("/getArticleByMonth")
    public Wrapper getArticleByMonth(@ApiParam(name = "monthDate", value = "归档的日期", required = false) @RequestParam(name = "monthDate", required = false) String monthDate) {
        if (StringUtils.isEmpty(monthDate)) {
            return Wrapper.illegal();
        }
        log.info("通过月份获取文章列表:{}", monthDate);
        List<BlogDto> resultList = blogService.getArticleByMonth(monthDate);
        return Wrapper.success(resultList);
    }
}
